package com.kz.springboot.common.response;

import com.alibaba.fastjson.JSON;

/**
 * json
 *
 * Created by wyz on 2016/7/13.
 */
public class JsonResponse {

    private int state;

    private String errorCode;

    private String errorMsg;

    private Object resultData;

    public JsonResponse(){};

    public JsonResponse(int state, String errorCode, String errorMsg, Object resultData){
        this.state=state;
        this.errorCode=errorCode;
        this.errorMsg=errorMsg;
        this.resultData=resultData;
    }

    public static JsonResponse R_200(){
        return new JsonResponse(200,"","",null);
    }

    public static JsonResponse R_200(JSON resultData){
        JsonResponse jsonResponse;
        if(null==resultData){
            jsonResponse = new JsonResponse(200,"","",null);
        }else{
            jsonResponse = new JsonResponse(200,"","",resultData);
        }
        return jsonResponse;
    }

    public static JsonResponse R_200(Object resultData){
        JsonResponse jsonResponse;
        if(null==resultData){
            jsonResponse = new JsonResponse(200,"","",null);
        }else{
            jsonResponse = new JsonResponse(200,"","",resultData);
        }
        return jsonResponse;
    }

    public static JsonResponse R_500(String errorCode, String errorMsg){
        return new JsonResponse(500,errorCode,errorMsg,null);
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public Object getResultData() {
        return resultData;
    }

    public void setResultData(Object resultData) {
        this.resultData = resultData;
    }

    @Override
    public String toString() {
        return "JsonResponse{" +
                "state=" + state +
                ", errorCode='" + errorCode + '\'' +
                ", errorMsg='" + errorMsg + '\'' +
                ", resultData= { " + resultData +" }"+
                '}';
    }
}
